<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>前后端交互</title>
    <script src="./js/axios.js"></script>
</head>

<body>

    <!-- 
        - async/await 是 ES7 引入的新语法,可以更加方便的进行异步操作
        - async 关键字用于函数上(async函数的返回值是Promise实例对象)
        - await 关键字用于async函数当中(await可以得到异步的结果)
     -->
    <script>
        axios.defaults.baseURL='http://localhost:3000'

        // axios.get('adata').then(ret => {
        //     console.log(ret.data)
        // })
        
        async function queryData(){
            // await 后面需要跟一个 Promise对象
            // var ret = await axios.get("adata")
            var ret = await new Promise(function(resolve,reject){
                setTimeout(function(){
                    resolve('nihao')
                },1000)
            })
            return ret;
        }

        queryData().then(function(data){
            console.log(data);
        });


    </script>

</body>

</html>